package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Company;
import com.itheima.service.CompanyListService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/companylist")
public class CompanyListController {
    @Reference
    private CompanyListService companyListService;
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = companyListService.pageQuery(queryPageBean);
        return pageResult;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Company company){
        try{
            companyListService.add(company);
            return new Result(true, "添加公司成功");//查询成功
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"添加公司失败");//查询失败
        }
    }

    @RequestMapping("/delete")
    public Result delete(Integer id){
        try{
            companyListService.delete(id);
            return new Result(true, "删除记录成功");//查询成功
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"删除记录失败");//查询失败
        }
    }

    @RequestMapping("/findAll")
    public Result findAll(){
        try{
            List<Company> list = companyListService.findAll();
            return new Result(true, "查询所有公司成功",list);//查询成功
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询所有公司失败");//查询失败
        }
    }


}
